home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 2
/
Mac Magazin and MacEasy Magazine CD - Issue 02.iso
/
Sharewarebibliothek
/
Applikationen
/
Alpha.5.81 folder
/
Tcl
/
SystemCode
/
grep.tcl
< prev
next >
Wrap
Text File
|
1994-05-31
|
2KB
|
64 lines
#================================================================================
# 'greplist' and 'grepfset' are used for batch searching from the "find" dialog.
# Hence, you really shouldn't mess with them unless you know what you are doing.
#================================================================================
proc greplist {args} {
set num [expr [llength $args] - 2]
set exp [lindex $args $num]
set arglist [lindex $args [expr $num + 1]]
set owin 0
set cid [scancontext create]
set cmd [lrange $args 0 [expr $num - 1]]
eval scanmatch $cmd {$cid $exp {
if (!$owin) {
set owin 1
new
set w [lindex [winNames -f] 0]
}
insertText -w $w "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
}
foreach f $arglist {
set fid [open $f]
scanfile $cid $fid
close $fid
}
scancontext delete $cid
}
proc grepfset {args} {
global fileSets
set num [expr [llength $args] - 2]
set exp [lindex $args $num]
set fset [lindex $args [expr $num + 1]]
eval greplist [lrange $args 0 [expr $num-1]] {$exp $fileSets($fset)}
}
proc grep {exp args} {
set files {}
foreach arg $args {
if {![catch {glob -t TEXT $arg} lst]} {
append files " " $lst
}
if {![catch {glob -t ttro $arg} lst]} {
append files " " $lst
}
}
if {$files==""} {return $lst}
set cid [scancontext create]
scanmatch $cid $exp {append lines "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
set lines ""
foreach f $files {
set fid [open $f]
scanfile $cid $fid
close $fid
}
scancontext delete $cid
return $lines
}